package com.situ.vivamarket.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.situ.vivamarket.dao.BrandDao;
import com.situ.vivamarket.model.Brand;
import com.situ.vivamarket.model.search.BrandSearchBean;
import com.situ.vivamarket.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    private BrandDao brandDao;
    @Autowired
    public void setBrandDao(BrandDao brandDao) {
        this.brandDao = brandDao;
    }

    @Override
    public List<Brand> getAllBrands(BrandSearchBean bsb, Page<?> p) {
        if(p==null){
            return brandDao.findAll(null);
        }
        try(Page<?>__= PageHelper.startPage(p.getPageNum(),p.getPageSize())){
            return brandDao.findAll(bsb);
        }
    }

    @Override
    public int deleteByIds(Integer[] ids) {
        return brandDao.deleteByIds(ids);
    }

    @Override
    public boolean add(Brand brand) {
        return brandDao.insert(brand)>0;
    }

    @Override
    public Brand findById(Integer id) {
        return brandDao.findById(id);
    }

    @Override
    public boolean update(Brand brand) {
        return brandDao.update(brand)>0;
    }
}
